package org.teamh.connection.json.handler;

import org.teamh.connection.json.event.JsonEventObject;
import org.teamh.game.Start;
import org.teamh.logic.datamodel.*;

public class TowerMappingHandler extends JsonMasterHandler {

	public TowerMappingHandler(Start start, DatamodelManager manager) {
		super(start, manager);
	}
	
	public boolean handleMsg(JsonEventObject json) {
		
		if (json.getSource().startsWith("TowerTypeTo")) {
			String ID = json.getSource();
			if(json.getProperty().equals("key")) {
				manager.getTowerMapping(ID).setName(json.getNewValue());
				return true;
			} else if (json.getProperty().equals("value")) {
				String descriptionID = json.getNewValue();
				TowerDescription description = new TowerDescription(descriptionID);
				manager.getTowerMapping(ID).addTowerDescription(description);
				manager.addTowerDescription(description);
				return true;
			}
			return false;
		} else {
			return false;
		}	
	}
}
